package com.zym.init.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zym.init.mapper.OperationLogMapper;
import com.zym.init.model.dto.PageDTO;
import com.zym.init.model.po.OperationLogPo;
import com.zym.init.model.query.OperationLogQuery;
import com.zym.init.model.vo.OperationLogVo;
import com.zym.init.service.OperationLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
* @author zou
* @description 针对表【operation_log(操作日志表)】的数据库操作Service实现
* @createDate 2024-11-20 04:05:05
*/
@Service
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLogPo>
    implements OperationLogService {

    /**
     * 获取列表
     *
     * @param query 查询条件
     * @return 列表
     */
    @Override
    public PageDTO<OperationLogVo> getPage(OperationLogQuery query) {
        // 分页查询
        Page<OperationLogPo> page = lambdaQuery()
                // ID
                .eq(query.getId() != null, OperationLogPo::getId, query.getId())
                // 操作人
                .eq(query.getUserId() != null, OperationLogPo::getUserId, query.getUserId())
                // 请求类型
                .eq(query.getType() != null, OperationLogPo::getType, query.getType())
                // 操作标题
                .like(StringUtils.hasLength(query.getTitle()), OperationLogPo::getTitle, query.getTitle())
                // 请求IP
                .eq(StringUtils.hasLength(query.getIp()), OperationLogPo::getIp, query.getIp())
                // 请求URL
                .like(StringUtils.hasLength(query.getUrl()), OperationLogPo::getUrl, query.getUrl())
                // 请求方法
                .like(StringUtils.hasLength(query.getMethod()), OperationLogPo::getMethod, query.getMethod())
                // 执行状态
                .eq(StringUtils.hasLength(query.getStatus()), OperationLogPo::getStatus, query.getStatus())
                // 追踪ID
                .eq(StringUtils.hasLength(query.getTraceId()), OperationLogPo::getTraceId, query.getTraceId())
                .page(query.toMpPageDefaultSortByCreateTimeDesc());
        // 封装返回
        return PageDTO.of(page, OperationLogVo.class);
    }
}




